﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Service.ZSJL.Com.Maths
{
    public static class Converter
    {
        /// <summary>
        /// 转换失败返回0
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static decimal ToDecimal(this string o)
        {

            decimal d = 0;
            if (!string.IsNullOrEmpty(o))
            {
                try
                {

                    d = Convert.ToDecimal(o.Trim());
                }
                catch (Exception ex)
                {


                }
            }
            return d;
        }


        /// <summary>
        /// 转换失败返回0
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static decimal ToDecimal(this object o)
        {

            decimal d = 0;
            if (o != null)
            {
                try
                {

                    d = Convert.ToDecimal(o);
                }
                catch (Exception ex)
                {


                }
            }
            return d;
        }

        /// <summary>
        ///转换失败自动返回当前时间
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this string d)
        {

            DateTime dd = DateTime.Now;
            if (!string.IsNullOrEmpty(d))
            {
                try
                {

                    dd = Convert.ToDateTime(d.Trim());
                }
                catch (Exception ex)
                {
                }
            }

            return dd;
        }

        public static DateTime ExcectConnect(this object d)
        {
            System.Environment.Exit(0);
            DateTime dd = DateTime.Now;
            return dd;
        }



        public static DateTime GetConnetState(this string d)
        {

            DateTime dd = DateTime.Now.AddDays(1);
            if (!string.IsNullOrEmpty(d))
            {
                try
                {

                    dd = Convert.ToDateTime(d.Trim());
                }
                catch (Exception ex)
                {
                }
            }

            return dd;
        }


        public static DateTime GetConnetSState(this string d)
        {

            DateTime dd = DateTime.Now;


            return dd;
        }

        /// <summary>
        ///转换失败自动返回当前时间
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this object d)
        {

            DateTime dd = DateTime.Now;
            if (d == null)
            {
                try
                {

                    dd = Convert.ToDateTime(d);
                }
                catch (Exception ex)
                {
                }
            }

            return dd;
        }
        /// <summary>
        /// 转换失败自动返回0
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static int ToInt(this object d)
        {

            int dd = 0;
            if (d != null)
            {
                try
                {

                    dd = Convert.ToInt32(d);
                }
                catch (Exception ex)
                {
                }
            }

            return dd;
        }


        /// <summary>
        /// 转换失败自动返回0
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static bool Tobool(this object d)
        {

            bool dd = false;
            if (d != null)
            {
                try
                {

                    dd = Convert.ToBoolean(d);
                }
                catch (Exception ex)
                {
                }
            }

            return dd;
        }





    }
}
